package com.drama.api.sys.download.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.drama.api.base.ApiIndex;
import com.drama.api.base.Constants;
import com.drama.api.base.R;
import com.drama.api.base.RestPage;
import com.drama.api.sys.download.domain.vo.DownloadExamineSearchVO;
import com.drama.api.sys.download.domain.vo.DownloadExamineStateBatchVO;
import com.drama.api.sys.download.domain.vo.DownloadExamineStateVO;
import com.drama.api.sys.download.domain.vo.DownloadExamineVO;
import com.drama.api.sys.download.service.IVideoDownloadExamineService;
import com.drama.util.BindingResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@Api( tags = ApiIndex.DownloadExamineController)
@RequestMapping(value = "/api/sys/download_examine")
@RestController
@SaCheckLogin
public class DownloadExamineController {
    @Autowired
    private IVideoDownloadExamineService service;


    @ApiOperation(value = "查询下载审核列表")
    @GetMapping(value = "/list")
    public R<RestPage<List<DownloadExamineVO>>> list(
            @ApiParam(value = "查询参数") @ModelAttribute DownloadExamineSearchVO searchVO) {
        List<DownloadExamineVO> list = service.getList(searchVO);
        RestPage restPage = new RestPage(new PageInfo(list), list);
        return new R(restPage);
    }


    @ApiOperation(value = "下载申请审核")
    @PostMapping(value = "/examine")
    public R examine(@ApiParam(value = "参数") @Valid @RequestBody DownloadExamineStateVO vo, BindingResult bindingResult) {
        R result = BindingResultUtil.BindingResult(bindingResult);
        if (result.getCode() == Constants.SYS_SUCCESS) {
            service.examine(vo);
        }
        return new R();
    }


    @ApiOperation(value = "下载申请审核-批量")
    @PostMapping(value = "/examine_batch")
    public R examine_batch(@ApiParam(value = "参数") @Valid @RequestBody DownloadExamineStateBatchVO vo, BindingResult bindingResult) {
        R result = BindingResultUtil.BindingResult(bindingResult);
        if (result.getCode() == Constants.SYS_SUCCESS) {
            service.examineBatch(vo);
        }
        return new R();
    }


}
